package com.gedi.data.RegexExpressionTest;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * @Author:RenPu
 * @Date: 2020/1/19 14:44
 * @Version: 1.0
 * @description:
 */

/**
 * 正则表达式的测试
 */
public class RegexTest {

    public static void main(String[] args) {
        final String regex = "^(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}).*\\[(.*)\\]\\s\"\\w*\\s(.*)\\sHTTP\\/1.1\"\\s(\\d{3}).*$";
        final String string = "27.19.74.143 - - [30/May/2013:17:38:20 +0800] \"GET /static/image/common/faq.gif HTTP/1.1\" 200 1127 ";

        final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
        final Matcher matcher = pattern.matcher(string);

        while (matcher.find()) {
            System.out.println("Full match: " + matcher.group(0));
            for (int i = 1; i <= matcher.groupCount(); i++) {
                System.out.println("Group " + i + ": " + matcher.group(i));
            }
        }

    }
}
